package com.ws.shop.entity;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.ws.shop.util.StringUtil;

public class Ticket extends BaseEntity{
	private int id;
	private String cardsn;
	private String cardpwd;
	private Date starttime;
	private Date endtime;
	private int beat;
	private int pointb;
	private int state;
	private Date addtime;
	
	public final static Map<String,String> STATE_DESCS = new HashMap<String,String>();
	
	static{
		STATE_DESCS.put("0", "未使用");
		STATE_DESCS.put("1", "已使用");
	}
	
	public Ticket(){}
	
	public Ticket(int id, String cardsn, String cardpwd, Date starttime,
			Date endtime, int beat, int pointb, int state) {
		this.id = id;
		this.cardsn = cardsn;
		this.cardpwd = cardpwd;
		this.starttime = starttime;
		this.endtime = endtime;
		this.beat = beat;
		this.pointb = pointb;
		this.state = state;
	}

	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getCardsn() {
		return cardsn;
	}
	public void setCardsn(String cardsn) {
		this.cardsn = cardsn;
	}
	public String getCardpwd() {
		return cardpwd;
	}
	public void setCardpwd(String cardpwd) {
		this.cardpwd = cardpwd;
	}
	public Date getStarttime() {
		return starttime;
	}
	public void setStarttime(Date starttime) {
		this.starttime = starttime;
	}
	public Date getEndtime() {
		return endtime;
	}
	public void setEndtime(Date endtime) {
		this.endtime = endtime;
	}
	public int getBeat() {
		return beat;
	}
	public void setBeat(int beat) {
		this.beat = beat;
	}
	public int getPointb() {
		return pointb;
	}
	public void setPointb(int pointb) {
		this.pointb = pointb;
	}
	public int getState() {
		return state;
	}
	public void setState(int state) {
		this.state = state;
	}
	
	public Date getAddtime() {
		return addtime;
	}

	public void setAddtime(Date addtime) {
		this.addtime = addtime;
	}

	public static Map<String, String> getNewTicket(int snlength, int sntype,
			int pwdlength, int pwdtype, int num) {
		Map<String, String> tickInfo = new HashMap<String,String>();
		if(num > 0){
			for(int i = 1;; i++){
				String snstr = null,pwdstr = null;
				if(sntype == 1){
					snstr = StringUtil.getCharRandomStr(snlength);
				}else if(sntype == 2){
					snstr = StringUtil.getNumRandomStr(snlength);
				}else if(sntype == 3){
					snstr = StringUtil.getRandomStr(snlength);
				}
				if(tickInfo.get(snstr) != null)
					continue;
				if(pwdtype == 1){
					pwdstr = StringUtil.getCharRandomStr(snlength);
				}else if(pwdtype == 2){
					pwdstr = StringUtil.getNumRandomStr(snlength);
				}else if(pwdtype == 3){
					pwdstr = StringUtil.getRandomStr(snlength);
				}
				tickInfo.put(snstr, pwdstr);
				if(tickInfo.size() == num)
					break;
			}
		}
		return tickInfo;
	}
	
}